home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / bin / list-devices < prev    next >
Encoding:
Text File  |  2007-02-15  |  2.1 KB  |  113 lines

  1. #! /bin/sh -e
  2. TYPE="$1"
  3.  
  4. case $TYPE in
  5.     cd|disk|partition|floppy|maybe-floppy)    ;;
  6.     *)
  7.         echo "Usage: $0 cd|disk|partition|floppy|maybe-floppy" >&2
  8.         exit 2
  9.         ;;
  10. esac
  11.  
  12. if [ -d /sys/block ] && type udevinfo >/dev/null 2>&1; then
  13.     syspaths=
  14.     case $TYPE in
  15.         partition)
  16.             for x in /sys/block/*/*; do
  17.                 [ -d "$x" ] || continue
  18.                 syspaths="${syspaths:+$syspaths }$x"
  19.             done
  20.             TYPE=disk
  21.             ;;
  22.         *)
  23.             for x in /sys/block/*; do
  24.                 [ -d "$x" ] || continue
  25.                 syspaths="${syspaths:+$syspaths }$x"
  26.             done
  27.             ;;
  28.     esac
  29.     for x in $syspaths; do
  30.         devpath="${x#/sys}"
  31.         match=false
  32.         case $TYPE in
  33.             maybe-floppy)
  34.                 TYPE=floppy
  35.                 ;;
  36.         esac
  37.         case $TYPE in
  38.             floppy)
  39.                 # TODO ugly special case for non-IDE floppies
  40.                 case $devpath in
  41.                     /block/fd[0-9]*)
  42.                         match=:
  43.                         ;;
  44.                 esac
  45.                 ;;
  46.         esac
  47.         if ! $match && [ "$TYPE" = cd ]; then
  48.             if udevinfo -q env -p "$devpath" 2>/dev/null | \
  49.                grep -q '^ID_CDROM='; then
  50.                 match=:
  51.             fi
  52.         fi
  53.         if ! $match; then
  54.             if udevinfo -q env -p "$devpath" 2>/dev/null | \
  55.                grep -q "^ID_TYPE=$TYPE"; then
  56.                 match=:
  57.             fi
  58.         fi
  59.         if ! $match && [ "$TYPE" = disk ]; then
  60.             case $devpath in
  61.                 /block/cciss\!*|/block/ida\!*|/block/rd\!*)
  62.                     match=:
  63.                     ;;
  64.             esac
  65.         fi
  66.         if $match; then
  67.             if ! name="$(udevinfo -q name -p "$devpath" \
  68.                     2>/dev/null)"; then
  69.                 name="$(printf %s "${devpath##*/}" | \
  70.                     sed 's,!,/,g')"
  71.             fi
  72.             echo "/dev/$name"
  73.         fi
  74.     done
  75. else
  76.     case $TYPE in
  77.         cd)
  78.             if [ -d /dev/cdroms ]; then
  79.                 find /dev/cdroms -type b
  80.             fi
  81.             ;;
  82.         disk)
  83.             if [ -d /dev/discs ]; then
  84.                 # busybox find has no -maxdepth
  85.                 find /dev/discs -type b | \
  86.                     grep -v '/.*/.*/.*/' || true
  87.             fi
  88.             ;;
  89.         partition)
  90.             if [ -d /dev/discs ]; then
  91.                 # busybox find has no -mindepth
  92.                 find /dev/discs -type b | \
  93.                     grep '/.*/.*/.*/' || true
  94.             fi
  95.             ;;
  96.         floppy)
  97.             if [ -d /dev/floppy ]; then
  98.                 find /dev/floppy -type b
  99.             fi
  100.             ;;
  101.         maybe-floppy)
  102.             # Without udev, we can't necessarily tell floppies
  103.             # from other kinds of disks, so we have to offer
  104.             # everything.
  105.             for x in /dev/floppy /dev/scsi /dev/ide /dev/discs; do
  106.                 if [ -d "$x" ]; then
  107.                     find "$x" -type b
  108.                 fi
  109.             done
  110.             ;;
  111.     esac
  112. fi
  113.